# == Schema Information
#
# Table name: users
#
#  id              :bigint(8)        not null, primary key
#  name            :string(255)
#  gender          :integer
#  status          :integer
#  kind            :integer
#  password_digest :string(255)
#  password_token  :string(255)
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#

class User < ApplicationRecord

  has_many :micoposts
  has_many :parises
  has_many :fellows
  has_many :fellowers, :through => :fellows, :source => :fellower


  validates_associated :micoposts
  validates_uniqueness_of :name
  validates :password, confirmation: true, length: {minimum: 6}, allow_blank: true
  validates_presence_of :name

  has_secure_password validations: false

  enum status: {active: 1, forbidden: 0}
  default_value_for :status, 1

  enum gender: {man: 1, woman: 2}
  default_value_for :gender, 1

  enum kind: {normal: 0, vip: 1}
  default_value_for :kind, 0

  scope :sorted, -> { order(created_at: :desc) }

end
